import xlsxwriter

class xls:
    def __init__(self,filename):
        self.filename = filename

    def main(self):
        #创建一个excel文件
        workbook = xlsxwriter.Workbook(self.filename)
        #创建工作表对象
        worksheet = workbook.add_worksheet()
        worksheet.set_column('A:A', 20)
        bold = workbook.add_format({'bold': True}) #加粗
        worksheet.write('A1', 'Hello', bold)
        worksheet.write('A2', 'World')
        worksheet.write('B2','中文测试',bold)
        worksheet.write(2,0,32)
        worksheet.write(3,0,32.1)
        worksheet.write(4,0,'=sum(A3:A4)')
        worksheet.insert_textbox('A6', 'Hello', {'font': {'bold': 1, 'italic': 1}})
        workbook.close()

if __name__ == '__main__':
    x = xls('test.xlsx')
    x.main()